class CloudFunction {
  constructor(name, data) {
    this.name = name;
    this.data = data || {};
  }

  call(callback) {
    wx.cloud.callFunction({
      name: this.name,
      data: this.data,
      success: res => callback(null, res),
      fail: err => callback(err)
    });
  }


callAsync() {
  return new Promise((resolve, reject) => {
    this.call((err, res) => {
      if (err) {
        reject(err);
      } else {
        resolve(res);
      }
    });
  });
}
}

module.exports = {
  CloudFunction
};